<html>

<#include "../header.ftl">

<body>

<form class="layui-form" action="">

    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-inline">
            <input value="${user.id}"    type="hidden" name="id">
            <input value="${user.name}"  type="text" name="name" lay-verify="required" lay-reqtext="用户名是必填项，岂能为空？" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input value="${user.password}"  type="password" name="password" lay-verify="password" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">请填写6到12位密码</div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">创建时间</label>
        <div class="layui-input-inline">
            <input <#if user.createTime?? && user.createTime!=""> value="${user.createTime}"</#if>
              type="text" name="createTime" id="createTime"  autocomplete="off" placeholder="请输入日期"
              class="layui-input">
        </div>
    </div>


    <div class="layui-input-item">
        <label class="layui-form-label">用户角色</label>
        <div class="layui-input-inline">
            <select name="roleId" >
                <option  value="">请选择用户角色</option>
                <option <#if   user.roleId==0>selected</#if>  value="0">班主任</option>
                <option <#if   user.roleId==1>selected</#if>  value="1">学生</option>
                <option <#if   user.roleId==2>selected</#if>  value="2">班长</option>
            </select>
        </div>

    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">是否禁用</label>
        <div class="layui-input-inline">
            <input <#if user.salt=='0'>checked</#if>  value="0"  type="radio" name="salt"  title="禁用">
            <input <#if user.salt=='1'>checked</#if>  value="1"  type="radio" name="salt"  title="不禁用">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,table = layui.table
            ,laydate = layui.laydate;
        form.render();
        //日期
        laydate.render({
            elem: '#createTime'
        });

        //自定义验证规则
        form.verify({
            name: function(value){
                if(value.length < 5){
                    return '标题至少得5个字符啊';
                }
            }
            ,password: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ]

        });


        //表单赋值
        layui.$('#LAY-component-form-setval').on('click', function(){
            form.val('example', {
                "name": "贤心" // "name": "value"
                ,"password": "123456"
                ,"interest": 1
                ,"like[write]": true //复选框选中状态
                ,"close": true //开关状态
                ,"sex": "女"
                ,"desc": "我爱 layui"
            });
        });


        //监听提交
        form.on('submit(demo1)', function(data){
            layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            })

            layerAjax('update',data.field,'userList')
            return false;
        });


    });
</script>

</body>
</html>